'''

网址：https://cdnmobibank.bankofbeijing.com.cn/cdn/mbank/FP/FP6/TFP6001.html?prdCode=23012008B

堆栈分析：
Promise.then
    XmWMXJ.l.request @main_library.dll.js:1

'''


import requests

cookies = {
    'sensorsdata2015jssdkcross': '%7B%22distinct_id%22%3A%22192529320ec668-0be38e38e38e39-4c657b58-1327104-192529320ed42f%22%2C%22first_id%22%3A%22%22%2C%22props%22%3A%7B%22%24latest_traffic_source_type%22%3A%22%E7%9B%B4%E6%8E%A5%E6%B5%81%E9%87%8F%22%2C%22%24latest_search_keyword%22%3A%22%E6%9C%AA%E5%8F%96%E5%88%B0%E5%80%BC_%E7%9B%B4%E6%8E%A5%E6%89%93%E5%BC%80%22%2C%22%24latest_referrer%22%3A%22%22%7D%2C%22identities%22%3A%22eyIkaWRlbnRpdHlfY29va2llX2lkIjoiMTkyNTI5MzIwZWM2NjgtMGJlMzhlMzhlMzhlMzktNGM2NTdiNTgtMTMyNzEwNC0xOTI1MjkzMjBlZDQyZiJ9%22%2C%22history_login_id%22%3A%7B%22name%22%3A%22%22%2C%22value%22%3A%22%22%7D%2C%22%24device_id%22%3A%22192529320ec668-0be38e38e38e39-4c657b58-1327104-192529320ed42f%22%7D',
    'BIGipServerwebfront.mbank-80': '!uN2OnS6ov4REXvK5t89h8h66sJxHOjXCpGMQoqOuzFNu94ra+4Dp+ZgDHjPgta1VgFyS9IujpLxvmw==',
    'JSESSIONID': '0000Ytt5d4k7M0aEeAX8lGq6ZEm:-1',
}

headers = {
    'Accept': 'application/json',
    'Accept-Language': 'zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6',
    'Access-Control-Allow-Origin': '*',
    'Connection': 'keep-alive',
    'Content-Type': 'application/json;charset=UTF-8',
    # 'Cookie': 'sensorsdata2015jssdkcross=%7B%22distinct_id%22%3A%22192529320ec668-0be38e38e38e39-4c657b58-1327104-192529320ed42f%22%2C%22first_id%22%3A%22%22%2C%22props%22%3A%7B%22%24latest_traffic_source_type%22%3A%22%E7%9B%B4%E6%8E%A5%E6%B5%81%E9%87%8F%22%2C%22%24latest_search_keyword%22%3A%22%E6%9C%AA%E5%8F%96%E5%88%B0%E5%80%BC_%E7%9B%B4%E6%8E%A5%E6%89%93%E5%BC%80%22%2C%22%24latest_referrer%22%3A%22%22%7D%2C%22identities%22%3A%22eyIkaWRlbnRpdHlfY29va2llX2lkIjoiMTkyNTI5MzIwZWM2NjgtMGJlMzhlMzhlMzhlMzktNGM2NTdiNTgtMTMyNzEwNC0xOTI1MjkzMjBlZDQyZiJ9%22%2C%22history_login_id%22%3A%7B%22name%22%3A%22%22%2C%22value%22%3A%22%22%7D%2C%22%24device_id%22%3A%22192529320ec668-0be38e38e38e39-4c657b58-1327104-192529320ed42f%22%7D; BIGipServerwebfront.mbank-80=!uN2OnS6ov4REXvK5t89h8h66sJxHOjXCpGMQoqOuzFNu94ra+4Dp+ZgDHjPgta1VgFyS9IujpLxvmw==; JSESSIONID=0000Ytt5d4k7M0aEeAX8lGq6ZEm:-1',
    'Origin': 'https://cdnmobibank.bankofbeijing.com.cn',
    'Referer': 'https://cdnmobibank.bankofbeijing.com.cn/cdn/mbank/FP/FP6/TFP6001.html?prdCode=23012008B',
    'Sec-Fetch-Dest': 'empty',
    'Sec-Fetch-Mode': 'cors',
    'Sec-Fetch-Site': 'same-origin',
    'User-Agent': 'Mozilla/5.0 (Linux; Android 13; SM-G981B) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Mobile Safari/537.36 Edg/129.0.0.0',
    'sec-ch-ua': '"Microsoft Edge";v="129", "Not=A?Brand";v="8", "Chromium";v="129"',
    'sec-ch-ua-mobile': '?1',
    'sec-ch-ua-platform': '"Android"',
    'sessionId': '9kSSzt3bwLs1vX7qqKSu8vE10472823',
    'tmf_apiname': 'MBS32003',
    'tmf_productid': '3393',
}

# data = '\x9aÎ:¥ßÈ\x15\x9e\x97Òýø\x17<<Aoî*§ÅÃ\x057Ù¡\x8b×óq>¬µ\x8c\x16iÞ»\x1e\x1a¹\x16ÝÈ\x87pv\x00æ\x8c\x98|ªÐH_ëM\aHò-ÝÊÿ\x10JÚVZÓ(ÔT*û¨v_\x89Ñ·I\x89\x04ï\x19]Ã\x89ö>·ÐZunÇ¤\x8b\x8c1ñ¯-\vs ðY=}'.encode()

import execjs

# 编译JavaScript文件
with open('某理财_处理请求响应二进制流.js', 'r', encoding='utf-8') as f:
    js_content = f.read()
ctx = execjs.compile(js_content)

## 调用JavaScript中的getRandom函数
# e = '{"tranCode":"MBS32003","prdCode":"23012008B","status":"0","consumerId":"MB","TMF_CHANNEL_FLAG":"1"}';
e = '{"tranCode":"MBS32123","prdCode":"23012008B","prdType":"1","consumerId":"MB","TMF_CHANNEL_FLAG":"1"}';
wbefore = ctx.call('W', e)
print('W：', wbefore)
wbeforeList = list(wbefore.values())
print('W：', wbeforeList)
wbeforeByteArray = bytearray(wbeforeList)
print('W：', wbeforeByteArray)


response = requests.post('https://cdnmobibank.bankofbeijing.com.cn/H',
                         cookies=cookies,
                         headers=headers,
                         data=wbeforeByteArray)
print(response.content)

